#!/usr/bin/env python
#coding=utf-8
#filename=3-11

'readTextFile.py -- read and display text file'

import os #导入OS模块
import string #导入string模块
# get filename
while True: #死循环
    fname = raw_input('Enter file name: ') #提示用户输入文件名，新增书中程序落了这句

    if os.path.exists(fname): 
        break #存在则跳出循环
    else:
        print"*** ERROR: '%s' not exists" % fname #判断用户输入的文件名是否已经存在

print
# attempt to open file for reading
#try:
fobj = open(fname, 'r')
#except IOError, e:
#    print"*** file open error:", e
#else:
    # display contents to the screen
for eachLine in fobj:
    print string.strip(eachLine)

fobj.close()
